home *** CD-ROM | disk | FTP | other *** search
- Path: news.nas.com!news
- From: gldnspud@kali.nas.com (Matt Scott)
- Newsgroups: comp.lang.c
- Subject: Function Prototype placement in source files
- Date: Fri, 16 Feb 1996 01:58:30 GMT
- Organization: Everyone's Software
- Message-ID: <4g0obg$78b@barad-dur.nas.com>
- NNTP-Posting-Host: kali.nas.com
- X-Newsreader: Forte Free Agent 1.0.82
-
- I have a question of style for everyone knowledgable and interested
- in the subject.
-
- My C Programming prof. at the community college, as well as the book
- he teaches with, put function prototypes inside main(). I didn't write
- it down or print it out, but here is what I remember of an example he
- wrote in the past to illustrate functions and static variables:
-
- (I'll try to emulate his brace style as much as I can -- sometimes it
- changes. Also, I don't know why he chose to use a float in this
- example,
- but he just did).
-
- #include <stdio.h>
-
- main()
- {
- float x;
- float one(void); /* 1 */
- void two(void); /* 2 */
-
- x = one();
- printf("i is now %.2f\n", x);
-
- two();
- }
-
- /* --------------------------------------------------------- */
-
- float one(void)
- {
- static float i = 10;
-
- i += 5;
- return i;
- }
-
- /* --------------------------------------------------------- */
-
- void two(void)
- {
- float f;
- int g;
- float one(void); /* 3 */
-
- for (g = 0; g < 6; ++g)
- {
- f = one();
- printf("i is now %.2f\n", f);
- }
-
- return;
- }
-
- /**************************************************************/
-
- My question is this: is there a compelling reason not to prototype
- functions above all of the functions using it, such as:
-
- float one(void);
- void two(void);
-
- main()
- ...
-
- In almost every instance of prototypes I've seen, they are declared
- outside of any function -- mostly above all other functions, and in
- a header file most often.
-
- Is there a good reason to do it the way he and the book do it?
-
- Thanks in advance for any thoughtful answers.
-
-
-
-